/**
 */
package com.dingpeikeji.quickdeer.core.modules.payinfo.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.dingpeikeji.quickdeer.core.common.config.Global;
import com.dingpeikeji.quickdeer.core.common.persistence.Page;
import com.dingpeikeji.quickdeer.core.common.utils.StringUtils;
import com.dingpeikeji.quickdeer.core.common.web.BaseController;
import com.dingpeikeji.quickdeer.core.modules.payinfo.entity.TPayinfo;
import com.dingpeikeji.quickdeer.core.modules.payinfo.service.TPayinfoService;

/**
 * 支付信息Controller
 * @author wuh
 * @version 2016-07-12
 */
@Controller
@RequestMapping(value = "${adminPath}/payinfo/tPayinfo")
public class TPayinfoController extends BaseController {

	@Autowired
	private TPayinfoService tPayinfoService;
	
	@ModelAttribute
	public TPayinfo get(@RequestParam(required=false) String discountid) {
		TPayinfo entity = null;
		if (StringUtils.isNotBlank(discountid)){
			entity = tPayinfoService.get(discountid);
		}
		if (entity == null){
			entity = new TPayinfo();
		}
		return entity;
	}
	
	@RequiresPermissions("payinfo:tPayinfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(TPayinfo tPayinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TPayinfo> page = tPayinfoService.findPage(new Page<TPayinfo>(request, response), tPayinfo); 
		model.addAttribute("page", page);
		return "modules/payinfo/tPayinfoList";
	}

	@RequiresPermissions("payinfo:tPayinfo:view")
	@RequestMapping(value = "form")
	public String form(TPayinfo tPayinfo, Model model) {
		model.addAttribute("tPayinfo", tPayinfo);
		return "modules/payinfo/tPayinfoForm";
	}

	@RequiresPermissions("payinfo:tPayinfo:edit")
	@RequestMapping(value = "save")
	public String save(TPayinfo tPayinfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tPayinfo)){
			return form(tPayinfo, model);
		}
		tPayinfoService.save(tPayinfo);
		addMessage(redirectAttributes, "保存支付信息成功");
		return "redirect:"+Global.getAdminPath()+"/payinfo/tPayinfo/?repage";
	}
	
	@RequiresPermissions("payinfo:tPayinfo:edit")
	@RequestMapping(value = "delete")
	public String delete(TPayinfo tPayinfo, RedirectAttributes redirectAttributes) {
		tPayinfoService.delete(tPayinfo);
		addMessage(redirectAttributes, "删除支付信息成功");
		return "redirect:"+Global.getAdminPath()+"/payinfo/tPayinfo/?repage";
	}

}
